import type { SysPost } from '@nbase/db';
import type { IPaginationResponse, IPost } from '@nbase/shared';

/**
 * SysPost -> IPost 映射（对外返回使用）
 */
export function toPost(post: SysPost): IPost {
  return {
    id: post.id,
    code: post.code,
    name: post.name,
    sort: post.sort,
    status: post.status,
    description: post.description,
    createdAt: post.createdAt?.toISOString(),
    updatedAt: post.updatedAt?.toISOString(),
  };
}

/**
 * 分页结果 SysPost -> IPost
 */
export function toPostPage(page: IPaginationResponse<SysPost>): IPaginationResponse<IPost> {
  return {
    ...page,
    items: page.items.map(toPost),
  };
}

